﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using BlogPlat.Controllers;

using BlogPlat.Model;
using BlogPlat.Model.Abstract;

namespace BlogPlat.Tests.Models
{
    public class FakeTagRepository : IRepository<Tag>
    {
        private List<Tag> _tags;

        public FakeTagRepository()
        {
            _tags = new List<Tag>();
        }

        public void Add(Tag newEntity)
        {
            _tags.Add(newEntity);
        }

        public void Delete(int id)
        {
            Tag tag = _tags.Where(t => t.TagID == id).SingleOrDefault();
            _tags.Remove(tag);
        }

        public Tag Get(int id)
        {
            return _tags.Where(t => t.TagID == id).SingleOrDefault();
        }

        public ICollection<Tag> List()
        {
            return _tags;
        }

        public void Save()
        {
            // not implemented for testing
        }

        public void Update(Tag entityToUpdate)
        {
            Tag tag = _tags.FirstOrDefault(t => t.TagID == entityToUpdate.TagID);
            _tags.Remove(tag);

            tag.TagName = entityToUpdate.TagName;
            tag.FriendlyUrl = entityToUpdate.FriendlyUrl;

            _tags.Add(tag);
        }
    }
}
